

/*
 * 获取平台公共接口的令牌
 * 必须是以exmobi为基座才可用,不建议使用require方式加载
 */
//访问码
var baseset = {
	//"accessCode":"8686c3f8-ce08-4345-89a8-9a36ba3e7e1f",
	"defaulCode":"acf54d1e-06c6-452c-ad87-40789e552d7a",
	"accessCode":"acf54d1e-06c6-452c-ad87-40789e552d7a",
	"bcsurl":"http://app.gx.csg.cn:8001"
};

 var authToken = "";
 var recal ;
 var paramObject="" ;
 
 var setAccessCode = function(str){
 	baseset.accessCode =str;
 }
 
 var setBcsurl = function(str){
 	baseset.bcsurl =str;
 }
 
 var setBaseSet = function(data){
 	baseset = data
 }
 
 //获取公共服务访问token
 var Cgs_token = function(cal,object){
	    authToken="";
 	    recal = cal;
 	    paramObject = object;
    	var csgData = {};
    	
    	csgData.accessCode = baseset.accessCode;
	    if (csgData.accessCode == "") {
	      A.showToast("请设置从南网管理平台申请的访问码");
		  return;
		}else{
			//获取bcs地址
			//初始化鉴权sdk
			CsgAuthUtil.init(csgData);
			
			var bcsajax = {};
			bcsajax.url =baseset.bcsurl;
			CsgAuthUtil.getToken(bcsajax,cgs_callbackFun);
		}
	}
	
//南网用户授权认证回调函数
var cgs_callbackFun = function(data) {
	var code = data.code;
	var token = data.token;
	var text = "";
	if (code == "0") {
		authToken = token;
		//回调外部函数
		if (paramObject!="")
		  recal(token,paramObject) 
		else
		  recal(token) 
	} else if (code == "1") {
	  text = "访问码不存在，回应状态码：" + code;
	  ExMobiWindow.alert(text)
	} else if (code == "2") {
	  text = "应用包不存在，回应状态码：" + code;
	  ExMobiWindow.alert(text)
	} else if (code == "3") {
	  text = "鉴权失败，回应状态码：" + code;
	  ExMobiWindow.alert(text)
	} else if (code == "4") {
	  text = "系统异常，回应状态码：" + code;
	  ExMobiWindow.alert(text)
	} else {
	  text = "回应状态码异常，值为：" + code;
	  ExMobiWindow.alert(text)
	}
}



